/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TransaksiHutang.java
 *
 * Created on Aug 15, 2010, 1:20:49 AM
 */
package com.ivanbiz.gui;

import com.ivanbiz.dao.PembelianDAO;
import com.ivanbiz.helper.CenterRenderer;
import com.ivanbiz.dao.PiutangDAO;
import com.ivanbiz.helper.RightRenderer;
import com.ivanbiz.helper.ServiceHelper;
import com.ivanbiz.impl.PembelianDAOImpl;
import com.ivanbiz.impl.PiutangDAOImpl;
import com.ivanbiz.model.ItemPembelian;
import com.ivanbiz.model.Pembelian;
import com.ivanbiz.model.Piutang;
import com.ivanbiz.model.PiutangHistory;
import com.ivanbiz.report.Report;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Aprisma
 */
public class TransaksiPiutang extends javax.swing.JInternalFrame {

    PiutangDAO piutangDAO = new PiutangDAOImpl();
    PembelianDAO pembelianDAO = new PembelianDAOImpl();
    List<Piutang> listPiutang = new ArrayList<Piutang>();
    List<PiutangHistory> listPiutangHistory = new ArrayList<PiutangHistory>();
    List<ItemPembelian> listItemPembelian = new ArrayList<ItemPembelian>();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    double sisaPiutang = 0;

    /** Creates new form TransaksiHutang */
    public TransaksiPiutang() {
        initComponents();
        updateData();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dialogNota = new javax.swing.JDialog();
        jScrollPane3 = new javax.swing.JScrollPane();
        tableItemPembelian = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePiutang = new javax.swing.JTable();
        buttonJatuhTempo = new javax.swing.JButton();
        buttonBelumLunas = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablePiutangHistory = new javax.swing.JTable();
        buttonBayar = new javax.swing.JButton();
        textBayar = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        labelNotaPembelian = new javax.swing.JLabel();
        textNotaPembelian = new javax.swing.JTextField();
        labelPemasok = new javax.swing.JLabel();
        textPelanggan = new javax.swing.JTextField();
        labelSisaPiutang = new javax.swing.JLabel();
        textSisaPiutang = new javax.swing.JTextField();
        labelJatuhTempo = new javax.swing.JLabel();
        textJatuhTempo = new javax.swing.JTextField();
        buttonPrint = new javax.swing.JButton();

        dialogNota.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        dialogNota.setTitle("Pembelian Barang");
        dialogNota.setModal(true);

        tableItemPembelian.setAutoCreateRowSorter(true);
        tableItemPembelian.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        tableItemPembelian.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(tableItemPembelian);

        javax.swing.GroupLayout dialogNotaLayout = new javax.swing.GroupLayout(dialogNota.getContentPane());
        dialogNota.getContentPane().setLayout(dialogNotaLayout);
        dialogNotaLayout.setHorizontalGroup(
            dialogNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        dialogNotaLayout.setVerticalGroup(
            dialogNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        setBorder(new org.jdesktop.swingx.border.DropShadowBorder());
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Transaksi Piutang");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("table Piutang"));

        tablePiutang.setAutoCreateRowSorter(true);
        tablePiutang.setFont(new java.awt.Font("Tahoma", 1, 11));
        tablePiutang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tablePiutang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablePiutangMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablePiutang);

        buttonJatuhTempo.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonJatuhTempo.setText("Jatuh Tempo");
        buttonJatuhTempo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonJatuhTempoActionPerformed(evt);
            }
        });

        buttonBelumLunas.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonBelumLunas.setText("Belum Lunas");
        buttonBelumLunas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonBelumLunasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(buttonJatuhTempo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addComponent(buttonBelumLunas)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonJatuhTempo)
                    .addComponent(buttonBelumLunas))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("table Piutang History"));

        tablePiutangHistory.setAutoCreateRowSorter(true);
        tablePiutangHistory.setFont(new java.awt.Font("Tahoma", 1, 11));
        tablePiutangHistory.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tablePiutangHistory);

        buttonBayar.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonBayar.setText(" Bayar");
        buttonBayar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonBayarActionPerformed(evt);
            }
        });

        textBayar.setFont(new java.awt.Font("Tahoma", 1, 14));
        textBayar.setText("jTextField1");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(textBayar, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonBayar)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonBayar)
                    .addComponent(textBayar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Hutang"));

        labelNotaPembelian.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelNotaPembelian.setText("Nota Pembelian");

        textNotaPembelian.setEditable(false);
        textNotaPembelian.setFont(new java.awt.Font("Tahoma", 1, 11));
        textNotaPembelian.setText("jTextField1");
        textNotaPembelian.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                textNotaPembelianMouseClicked(evt);
            }
        });

        labelPemasok.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelPemasok.setText("Pemasok");

        textPelanggan.setEditable(false);
        textPelanggan.setFont(new java.awt.Font("Tahoma", 1, 11));
        textPelanggan.setText("jTextField1");

        labelSisaPiutang.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelSisaPiutang.setText("Sisa Hutang");

        textSisaPiutang.setEditable(false);
        textSisaPiutang.setFont(new java.awt.Font("Tahoma", 1, 11));
        textSisaPiutang.setText("jTextField1");

        labelJatuhTempo.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelJatuhTempo.setText("Jatuh Tempo");

        textJatuhTempo.setEditable(false);
        textJatuhTempo.setFont(new java.awt.Font("Tahoma", 1, 11));
        textJatuhTempo.setText("jTextField1");

        buttonPrint.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonPrint.setText("Print");
        buttonPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonPrintActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelSisaPiutang)
                    .addComponent(labelPemasok)
                    .addComponent(labelJatuhTempo)
                    .addComponent(labelNotaPembelian))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textJatuhTempo, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                    .addComponent(textPelanggan, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                    .addComponent(textSisaPiutang, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(textNotaPembelian, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonPrint)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonPrint)
                    .addComponent(textNotaPembelian, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNotaPembelian))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textPelanggan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelPemasok))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textSisaPiutang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelSisaPiutang))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textJatuhTempo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelJatuhTempo))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-550)/2, 800, 550);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonBelumLunasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBelumLunasActionPerformed
        try {
            updateData();
            listPiutang = piutangDAO.getByBelumLunas();
            updateTablePiutang();
        } catch (Exception ex) {
            Logger.getLogger(TransaksiPiutang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonBelumLunasActionPerformed

    private void buttonJatuhTempoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonJatuhTempoActionPerformed
        try {
            updateData();
            listPiutang = piutangDAO.getByJatuhTempo(ServiceHelper.getDateNow());
            updateTablePiutang();
        } catch (Exception ex) {
            Logger.getLogger(TransaksiPiutang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonJatuhTempoActionPerformed

    private void buttonBayarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBayarActionPerformed
        try {
            Piutang piutang = (Piutang) listPiutang.get(tablePiutang.getSelectedRow());
            if (Double.parseDouble(textBayar.getText()) > sisaPiutang || Double.parseDouble(textBayar.getText()) <= 0) {
                JOptionPane.showMessageDialog(null, "Jumlah Bayar Melebihi Sisa Piutang !!!");
            } else {
                piutangDAO.bayarPiutang(piutang, Double.parseDouble(textBayar.getText().toUpperCase()));
                sisaPiutang = 0;
                updateData();
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Terjadi Error Mungkin Harus Angka Atau Data Tidak Masuk");
            Logger.getLogger(TransaksiPiutang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonBayarActionPerformed

    private void tablePiutangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablePiutangMouseClicked
        try {
            buttonBayar.setEnabled(true);
            buttonPrint.setEnabled(true);
            Piutang piutang = (Piutang) listPiutang.get(tablePiutang.getSelectedRow());
            textNotaPembelian.setText(piutang.getPembelian().getKode());
            textPelanggan.setText(piutang.getPembelian().getSupplier().getKode() + "(" + piutang.getPembelian().getSupplier().getNama() + ")");
            textJatuhTempo.setText("" + simpleDateFormat.format(piutang.getJatuhTempo()));
            sisaPiutang = piutang.getSisaPiutang();
            textSisaPiutang.setText("Rp " + numberFormat.format(piutang.getSisaPiutang()) + ",00");
            listPiutangHistory = piutangDAO.getDataByEquals(PiutangHistory.class, "piut", piutang);
            updateTablePiutangHistory();
        } catch (Exception ex) {
            Logger.getLogger(TransaksiPiutang.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_tablePiutangMouseClicked

    private void buttonPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPrintActionPerformed
        Report report = new Report();
        report.setNoNota(textNotaPembelian.getText().toUpperCase());
        report.reportPiutangByNota();
    }//GEN-LAST:event_buttonPrintActionPerformed

    private void textNotaPembelianMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_textNotaPembelianMouseClicked
        try {
            Pembelian pembelian = (Pembelian) pembelianDAO.getDataByEqual(Pembelian.class, "kode", textNotaPembelian.getText().toUpperCase());
            listItemPembelian = pembelian.getItemPembelian();
            updateTableItemPembelian();
            dialogNota.setSize(600, 400);
            dialogNota.setVisible(true);
        } catch (Exception ex) {
            Logger.getLogger(TransaksiPiutang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_textNotaPembelianMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonBayar;
    private javax.swing.JButton buttonBelumLunas;
    private javax.swing.JButton buttonJatuhTempo;
    private javax.swing.JButton buttonPrint;
    private javax.swing.JDialog dialogNota;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel labelJatuhTempo;
    private javax.swing.JLabel labelNotaPembelian;
    private javax.swing.JLabel labelPemasok;
    private javax.swing.JLabel labelSisaPiutang;
    private javax.swing.JTable tableItemPembelian;
    private javax.swing.JTable tablePiutang;
    private javax.swing.JTable tablePiutangHistory;
    private javax.swing.JTextField textBayar;
    private javax.swing.JTextField textJatuhTempo;
    private javax.swing.JTextField textNotaPembelian;
    private javax.swing.JTextField textPelanggan;
    private javax.swing.JTextField textSisaPiutang;
    // End of variables declaration//GEN-END:variables

    private void updateData() {
        buttonBayar.setEnabled(false);
        buttonPrint.setEnabled(false);
        textNotaPembelian.setText("");
        textPelanggan.setText("");
        textSisaPiutang.setText("");
        textBayar.setText("");
        textJatuhTempo.setText("");
        listPiutang.clear();
        updateTablePiutang();
        listPiutangHistory.clear();
        updateTablePiutangHistory();
    }

    private void updateTableItemPembelian() {
        String[] judul = {"No", "Kode", "Nama", "Satuan", "Jumlah", "Harga", "Sub Total"};
        Object[][] isi = new Object[listItemPembelian.size()][7];
        int x = 0;
        int no = 0;
        for (ItemPembelian itemPembelian : listItemPembelian) {
            isi[x][0] = no += 1;
            isi[x][1] = itemPembelian.getBarang().getKode();
            isi[x][2] = itemPembelian.getBarang().getNama();
            isi[x][3] = itemPembelian.getBarang().getSatuan().getNama();
            isi[x][4] = itemPembelian.getJumlah();
            isi[x][5] = "Rp " + numberFormat.format(itemPembelian.getHarga()) + ",00";
            isi[x][6] = "Rp " + numberFormat.format(itemPembelian.getHarga() * itemPembelian.getJumlah()) + ",00";
            x++;
        }
        tableItemPembelian.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tableItemPembelian.getColumnModel().getColumn(0);
        column0.setPreferredWidth(50);
        column0.setMaxWidth(50);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column1 = tableItemPembelian.getColumnModel().getColumn(1);
        column1.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tableItemPembelian.getColumnModel().getColumn(3);
        column3.setCellRenderer(new CenterRenderer());
        TableColumn column4 = tableItemPembelian.getColumnModel().getColumn(4);
        column4.setCellRenderer(new CenterRenderer());
        TableColumn column5 = tableItemPembelian.getColumnModel().getColumn(5);
        column5.setCellRenderer(new RightRenderer());
        TableColumn column6 = tableItemPembelian.getColumnModel().getColumn(6);
        column6.setCellRenderer(new RightRenderer());
    }

    private void updateTablePiutang() {
        String[] judul = {"No", "Nota Pembelian", "Pemasok", "Sisa Piutang", "Jatuh Tempo"};
        Object[][] isi = new Object[listPiutang.size()][5];
        int x = 0;
        int no = 0;
        for (Piutang piutang : listPiutang) {
            no += 1;
            isi[x][0] = no;
            isi[x][1] = piutang.getPembelian().getKode();
            isi[x][2] = piutang.getPembelian().getSupplier().getNama();
            isi[x][3] = "Rp " + numberFormat.format(piutang.getSisaPiutang()) + ",00";
            isi[x][4] = simpleDateFormat.format(piutang.getJatuhTempo());
            x++;
        }
        tablePiutang.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tablePiutang.getColumnModel().getColumn(0);
        column0.setPreferredWidth(75);
        column0.setMaxWidth(75);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column1 = tablePiutang.getColumnModel().getColumn(1);
        column1.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tablePiutang.getColumnModel().getColumn(3);
        column3.setCellRenderer(new RightRenderer());
        TableColumn column4 = tablePiutang.getColumnModel().getColumn(4);
        column4.setCellRenderer(new CenterRenderer());
    }

    private void updateTablePiutangHistory() {
        String[] judul = {"Tanggal Bayar", "Piutang", "Sudah Bayar", "Sisa Piutang"};
        Object[][] isi = new Object[listPiutangHistory.size()][4];
        int x = 0;
        int no = 0;
        for (PiutangHistory piutangHistory : listPiutangHistory) {
            no += 1;
            isi[x][0] = simpleDateFormat.format(piutangHistory.getCreateDate());
            isi[x][1] = "Rp " + numberFormat.format(piutangHistory.getPiutang()) + ",00";
            isi[x][2] = "Rp " + numberFormat.format(piutangHistory.getBayar()) + ",00";
            isi[x][3] = "Rp " + numberFormat.format(piutangHistory.getSisa()) + ",00";
            x++;
        }
        tablePiutangHistory.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tablePiutangHistory.getColumnModel().getColumn(0);
        column0.setPreferredWidth(125);
        column0.setMaxWidth(125);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column1 = tablePiutangHistory.getColumnModel().getColumn(1);
        column1.setCellRenderer(new RightRenderer());
        TableColumn column2 = tablePiutangHistory.getColumnModel().getColumn(2);
        column2.setCellRenderer(new RightRenderer());
        TableColumn column3 = tablePiutangHistory.getColumnModel().getColumn(3);
        column3.setCellRenderer(new RightRenderer());
    }
}
